﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Text;

namespace DevEx.Thanh.Class
{
    class CRoleController
    {
        QLVTDataContext objDataContext;
        public IQueryable<tblRole> SelectAllRecord()
	    {
		    try {
			    return (from u in objDataContext.tblRoles select u);
		    } catch (Exception ex)
		    {
		        return null;
		    }
	    }
        public tblRole SelectRecordByID(int _id)
	    {
		    try {
			    return (from u in objDataContext.tblRoles where u.ID_Role == _id select u).Single();
		    } catch (Exception ex)
		    {
		        return null;
		    }
	    }
        public int InsertRecord(tblRole LocalTable)
        {
            try
            {
                objDataContext.tblRoles.InsertOnSubmit(LocalTable);
                objDataContext.SubmitChanges();
                return LocalTable.ID_Role;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        public void UpdateRecord(tblRole LocalTable)
        {
            try
            {
                objDataContext.tblRoles.Attach(LocalTable);
                objDataContext.Refresh(RefreshMode.KeepCurrentValues, LocalTable);
                objDataContext.SubmitChanges(ConflictMode.ContinueOnConflict);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void UpdateRecordWithoutAttach(tblRole LocalTable)
        {
            try
            {
                objDataContext.Refresh(RefreshMode.KeepCurrentValues, LocalTable);
                objDataContext.SubmitChanges(ConflictMode.ContinueOnConflict);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public CRoleController()
        {
            objDataContext = new QLVTDataContext( );
        }
        public CRoleController(QLVTDataContext  _obj)
        {
            objDataContext = _obj;
        }
    }
}
